use actix_web::{error::ErrorInternalServerError, web, Responder, Result};

use crate::{
    api_add, api_delete, api_edit, api_get_in_page,
    config::get_page_size,
    database::DbPool,
    route::form::{
        path::PageForm,
        user::{NewUserForm, UserForm},
    },
    service::class,
};

pub fn config_admin_user(cfg: &mut web::ServiceConfig) {
    cfg.service(
        web::scope("/user")
            .route("/page/{page}", web::get().to(get_users))
            .route("/add", web::post().to(add_user))
            .route("/edit", web::post().to(edit_user))
            .route("/delete", web::post().to(delete_user)),
    );
}

api_get_in_page!(get_users, PageForm, class::user::get_in_page);
api_add!(add_user, NewUserForm, class::user::add);
api_edit!(edit_user, UserForm, class::user::upd);
api_delete!(delete_user, UserForm, class::user::del);
